package com.example.service;

import com.example.entity.Download;
import com.example.mapper.DownloadMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 业务层方法
 */
@Service
public class DownloadService {

    @Resource
    private DownloadMapper downloadMapper;

    public void add(Download download) {
        downloadMapper.insert(download);
    }

    public void updateById(Download download) {
        downloadMapper.updateById(download);
    }

    public void deleteById(Integer id) {
        downloadMapper.deleteById(id);
    }

    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids) {
            downloadMapper.deleteById(id);
        }
    }

    public Download selectById(Integer id) {
        return downloadMapper.selectById(id);
    }

    public List<Download> selectAll(Download download) {
        return downloadMapper.selectAll(download);
    }

    public PageInfo<Download> selectPage(Download download, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Download> list = downloadMapper.selectAll(download);
        return PageInfo.of(list);
    }

}
